package com.woniuxy.microcontentserver.messagemsg.service.impl;

import com.woniuxy.microcontentserver.bean.MessageBean;
import com.woniuxy.microcontentserver.messagemsg.mapper.MessageMapper;
import com.woniuxy.microcontentserver.messagemsg.service.IMessageService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Transactional(readOnly = true)
@Service
public class MessageServiceImpl implements IMessageService {

    @Resource
    private MessageMapper messageMapper;

    /**
     * 查询所有资讯
     * @param
     * @return
     */
    @Override
    public List<MessageBean> findAll() {

        return messageMapper.findAll();
    }

    /**
     * 根据id查询资讯
     * @param id
     * @return
     */
    @Override
    public MessageBean getOneById(Long id) {
        return messageMapper.getOneById(id);
    }


    /**
     * 添加资讯
     * @param messageBean
     * @return
     */
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor =Exception.class)
    @Override
    public int addMessageBean(MessageBean messageBean) {
        return messageMapper.addMessageBean(messageBean);
    }

    /**
     * 修改资讯
     * @param messageBean
     * @return
     */
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor =Exception.class)
    @Override
    public int updateMessageBean(MessageBean messageBean) {
        return messageMapper.updateMessageBean(messageBean);
    }


    /**
     * 删除资讯
     * @param id
     * @return
     */
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor =Exception.class)
    @Override
    public int deleteMessageBean(Long id) {

        return messageMapper.deleteMessageBean(id);
    }
}
